impl Solution {
    pub fn next_larger_nodes(head: Option<Box<ListNode>>) -> Vec<i32> {
        let mut res = vec![];
        let mut cur = &head;
        let mut stack: Vec<[i32; 2]> = vec![];
        let mut count: usize = 0;

        while cur.is_some() {
            let v = cur.as_ref().unwrap().val;
            while !stack.is_empty() && stack.last().unwrap()[1] < v {
                res[stack.last().unwrap()[0] as usize] = v;
                stack.pop();
            }

            stack.push([count as i32, v]);
            res.push(0);
            cur = &cur.as_ref().unwrap().next;
            count += 1;
        }

        res
    }
}